/**
 * @author yzhou2
 */
/*
var QS_Style={
    redFontColor: '#ff0000',
    redFontBG: '#FFC8C8',
    greenFontColor: '#008000',//
    greenFontBG: '#CDFFD7',
    normalFontBG:'#ccc',
    layouthelperBG:"#fff",
    redFlashFontColor:'#ff0000',
    greenFlashFontColor:'#008000',
    normalFlashFontColor:'#121212'
};*/
var QS_toDate=function(d){
    var d = new Date(d);
    return QS_DateFmt.getWeekDay(d)+' '+QS_DateFmt.getDateString(d);
};
var QS_toTime=function(value){
	if(isNaN(value)){
		return "--";
	}
	var d=new Date();
	var t = new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime() + parseInt(value) * 1000;
    var dt = new Date(t);
    return (dt == null) ? "--" :QS_DateFmt.getTimeString(dt);
};
var QS_splitDataByLen=function(d,len){
	var sign=d<0?'-':'';
	d=Math.abs(d);
	var dArr = (d + "").split(".");
	var l1 = dArr[0].length;
	dArr[0]=QS_NumFmt.Fmt2(dArr[0],false,"",0);
	if(l1>=len){
		d=dArr[0];
	}else{
		var d2 = parseFloat("0." + dArr[1], 10).toFixed(len - l1);
		dArr[1] = d2.split(".")[1];
		d = dArr.join('.');
	}
	return sign+d;
};
var QS__Formatter=function(d,dataType,secType){
	dataType=typeof dataType=='undefined'?'f':dataType;//if dataType is empty, that means the dataType is a default "float".
    if(typeof d=='undefined'|| d=='--'){
        return '--';
    }
    switch(dataType){
        case 'f2':{
            d = QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d,10).toFixed(2);
            break;
        }
        case 'f4':{
            if (Math.abs(d) * 100 < 1 && d != 0) {
                d = QS_NumFmt.Fmt2(d,false,"",4);//parseFloat(d, 10).toFixed(4);
            }else {
                d = QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d, 10).toFixed(2);
            }
            break;
        }
        case 'i':
		    d = QS_NumFmt.Fmt2(d,false,"",0); 
			break; 
        case 's':{
            break;
        }
        case 'sf':{
			if(secType=='20'){
				d=QS_splitDataByLen(d,5);
			}else{
				d = QS_NumFmt.Fmt2(d,false,"",2);
			}
            break;
        }
        case 'd':{
            d = QS_toDate(d.replace(/-/g,'/'));
            break;
        }
        case 't':{
            d = QS_toTime(d);
            break;
        }
        case 'm':{
			d=QS_NumFmt.Fmt2(d,true," ",2);
			/*
            d=parseInt(d,10);
            if(d>100000){
                d=(d/1000000).toFixed(1)+' mil';
            }*/
            break;
        }
        case '%':{
            d=QS_NumFmt.Fmt2(d,false,"",2);//parseFloat(d,10).toFixed(2)+'%';
            break;
        }
        case 'dm':{
			d=QS_NumFmt.Fmt2(d*1000000,true," ",2);
            /*d=parseFloat(d,10);
            if(d>1000){
                d=(d/1000).toFixed(1)+' bil';
            }else{
                d=d.toFixed(1)+' mil';
            }*/
            break;
        }
        case 'star':{
            d = '<span class="star'+d+'"></span>';
            break;
        }
        case 'sty':{
            d = '<span class="sty'+d+'"></span>';
            break;
        }
        case 'exch':{
           d = typeof d=='undefined'||!gExchangeMap[d]?"--":gExchangeMap[d];
            break;
        }
        case 'cat':{
            var a = d.split(' ');                 
            a.splice(0,1);
            d = a.join(' ');
            break;
        }
        default:{
            if(!isNaN(d)){
				d=QS_NumFmt.Fmt2(d,true," ",2);
                /*d=parseFloat(d,10);
                if(d>100000000){
                    d=(d/1000000000).toFixed(1)+' bil';
                }
                else if(d>100000){
                    d=(d/1000000).toFixed(1)+' mil';
                }else{
                    d=d.toFixed(2);
                }*/
            }
            break;
        }
    }
    return d;
};
var QS_Formatter=function(gkey,field,dataType){
    var d=typeof gkey=='undefined'?{}:(typeof gData[gkey]=='undefined'?{}:gData[gkey]);
    var marketQuoteData=(typeof gkey=='undefined'||gkey==null)?{}:push.proxy.getMarketQuoteData(gkey);
    var secType=typeof d['type']=='undefined'?-1:d['type'];
    if(field.length==2){
        var val1,val2;
        if(typeof marketQuoteData[field[0]]!='undefined'){
            val1=marketQuoteData[field[0]].value;
        }else{
			val1=d[field[0]];
		}
        if(typeof marketQuoteData[field[1]]!='undefined'){
            val2=marketQuoteData[field[1]].value;
        }else{
			val2=d[field[1]];
		}
        return QS__Formatter(val1,dataType,secType)+"-"+QS__Formatter(val2,dataType,secType);
    }else{
        var val1;
        if(typeof marketQuoteData[field[0]]!='undefined'){
            val1=marketQuoteData[field[0]].value;
        }else{
			val1=d[field[0]];
		}
        return QS__Formatter(val1,dataType,secType);
    }
};
if(!QS){
    var QS={};
}
QS.Head=function(container,config,callback){
    this.html=null;//
    this.el=null;
    this.nameEl=null;
    this.symbolEl=null;
	this.secTypeEl=null;
    this.config={
		isFormatName:true,
		showSecType:false
	};
    this.callback={};
    if (config) {
       $.extend(this.config,config)
    }
    if (callback) {
       $.extend(this.callback,callback)
    }
    this.container=container;
    this.init();
};
QS.Head.prototype={
    init:function(){
		this.html='<div class="rtq-quotes-hd"><div class="name-symbol"><h1 class="name"></h1><span class="symbol"></span></div>'+(this.config.showSecType?'<span class="sectype"></span>':'')+'</div>';
        this.el=$(this.html).appendTo(this.container);
        this.nameEl=this.el.find('.name');
        this.symbolEl=this.el.find('.symbol');
		if(this.config.showSecType){
			this.secTypeEl=this.el.find('.sectype');
		}
    },      
    getHeight:function(){
        return this.el.outerHeight(true);
    },
    changeInfo:function(info){
		var name=info.companyName;
		if(this.config.isFormatName&&name!=""){
			name=formatNameString(info.companyName);
		}
		this.nameEl[0].innerHTML=name;
		if(info.companyName!=info.symbol){
			this.symbolEl[0].innerHTML=info.symbol;
		}
		if(this.secTypeEl!=null&&info.secType!=""){
			var t=QS_Lang.quote;
			this.secTypeEl[0].innerHTML=t["sectype"+info.secType.toLowerCase()]||'';
		}
    },
    show:function(){
        this.el.show();
    },
    hide:function(){
        this.el.hide();
    },
    clear:function(){
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};
QS.QuoteUnique=function(container,config,callback){
    this.el=null;
	this.priceEl=null;
	this.changeEl=null;
	this.changeElOutWidth=null;
	this.changeDomPaddingWidth=0;
    this.config={
		showNewsLink:false,
		showCurrency:true,
		showTimeZone:false,
		showExtendHour:true
	};
    this.callback={};
    this.domMap={};
    this.dpfMap={};
    this.html=null;
    this.dataPoints=null;
    this.width=0;
    this.height=0;
    this.container=container;
    if(config){
        $.extend(this.config,config);
    }
    if(callback){
        $.extend(this.callback,callback);
    }
    this.init();
};
QS.QuoteUnique.prototype={
    init:function(){
        var self=this;
        this.dataPoints=this.buildDataPoints();
        this.html=this.buildInnerHTML();
        this.el=$(this.html).appendTo(this.container);
        var d;
        for(var i=0,l=this.dataPoints.length;i<l;i++){
            d=this.dataPoints[i];
			if(d==null||d.isStatic)continue;
            this.domMap[d.val]=this.el.find('span[domid="'+d.val+'"]')[0];
            this.dpfMap[d.val]=d.dataType;
        }
        this.chgPDom=$(this.domMap['Chg']).closest('div')[0];
        this.domMap['Chg%']=this.el.find('span[domid="Chg"]')[1];
        this.dpfMap['Chg%']=this.dpfMap['Chg'];
        this.LastPriceTxtDom=this.el.find('.cx .lastText');
		this.priceEl=this.el.find('.cx').eq(0);
		this.changeEl=this.el.find('.cx').eq(1);
		this._initVauleForIE7();
        this.container.css({width:this.getWidth(),height:this.getHeight()});
        if (this.config.showNewsLink) {
            this.el.find('span[domid="news"]').bind('click.quoteUnique',function(){
                //console.log("click");
                if(typeof self.callback.onNewsClick=='function'){
                    self.callback.onNewsClick('All');
                }
            });
        }
    },
	_initVauleForIE7:function(){
		if($.browser.msie && parseInt($.browser.version) < 8){
			this.changeChildrenEl=this.changeEl.find('.chg').children();
			this.changeDomPaddingWidth=this.changeEl.outerWidth(true)-this.changeEl.width();//get changel padding,border and margin width
		}
	},
    buildInnerHTML:function(){
        var html='<div class="qs-quote-unique clearfix">',d;
        for(var i=0,l=this.dataPoints.length;i<l;i++){
            var d=this.dataPoints[i];
			if(d==null){
				continue;
			}
            var valTxt=d.valTxt||'--';
            if(d.val=='Chg'){
                html += '<div class="' + d.cls + '"><div><span class="rtq-tt '+(d.tCls?d.tCls:'')+'">' + d.txt + '</span></div><div class="chg"><span class="rtq-d change ' + (d.vCls?d.vCls:'') + '" domid="' + d.val + '">'+valTxt+'</span><span class="rtq-d changep ' + d.vCls + '" domid="' + d.val + '">'+valTxt+'</span><sup>%</sup></div></div>';
            }else{
                html +='<div class="'+d.cls+'"><div><span class="rtq-tt '+(d.tCls?d.tCls:'')+'">'+d.txt+'</span></div><div><span class="rtq-d '+(d.vCls?d.vCls:'')+'" domid="'+d.val+'">'+ valTxt +'</span></div></div>';
            }
        }
        html+='</div>';
        return html;
    },
    buildDataPoints:function(){
		var t=QS_Lang.quote;
         return [{val:'LastPrice',txt:t.qlastprice,cls:'cx',tCls:'lastText',dataType:'sf',vCls:'big'},// 'sf' decimals by sec type
        {val:'Chg',txt:t.daychange,cls:'cx',dataType:'sf',vCls:'big'},
        //{val:'Chg%',txt:'Day Change',cls:'cx',dataType:'f',dataFormat:'#.0000',vCls:'big'},
        {val:'AfterTxt',txt:'',cls:'afd',dataType:'s'},
        this.config.showExtendHour?{val:'Date',txt:'',cls:'aft',dataType:'d'}:{val:'TradeDate',txt:'',cls:'aft',dataType:'d'},
        this.config.showExtendHour?{val:'Time',txt:'',cls:'aft',dataType:'t'}:{val:'TradeTime',txt:'',cls:'aft',dataType:'t'},
		this.config.showTimeZone?{val:'TimeZone',txt:'',cls:'aft',dataType:'s',valTxt:'GMT',isStatic:true}:null,
        this.config.showCurrency?{val:'currency',txt:'',cls:'cur',dataType:'s'}:null,
        this.config.showNewsLink?{val:'news',txt:'',cls:'newslink',dataType:'s',valTxt:t.news,isStatic:true}:null]
    },
    changeLastText:function(lastText){
        this.LastPriceTxtDom[0].innerHTML=lastText;
    },
    getWidth:function(){
        if (this.width == 0) {
            this.width = this.el.outerWidth(true);
        }
        return this.width;
    },
    getHeight:function(){
        if(this.height==0){
            this.height=this.el.outerHeight(true);
        }
        return this.height; 
    },
    updateData:function(gkey,data){
		var d=typeof gkey=='undefined'?{}:(typeof gData[gkey]=='undefined'?{}:gData[gkey]);
		var marketQuoteData=(typeof gkey=='undefined'||gkey==null)?{}:push.proxy.getMarketQuoteData(gkey);
		var secType=typeof d['type']=='undefined'?-1:d['type'];
        var el;
        for(var field in data){
            el=this.domMap[field];
            if(el){
				var originalValue=typeof marketQuoteData[field]!='undefined'?marketQuoteData[field].value:d[field];
				if(field=='Chg'){
                    this._setColorForChg(originalValue||'--',this.chgPDom);
					if(!isNaN(originalValue)){
						originalValue= Math.abs(originalValue);//change value need positive 
					}
                }
				var formatValue=QS__Formatter(originalValue,this.dpfMap[field],secType);
                el.innerHTML=formatValue;
            }
        }
        if(!this.config.showExtendHour||(this.domMap['AfterTxt']&&(!gData[gkey]||gData[gkey].showAfter==0||typeof gData[gkey].showAfter=='undefined'))){
            this.domMap['AfterTxt'].innerHTML='';
        }
        
    },
    _setColorForChg:function(value,dom){
        if(value>0&&dom.className!='chg rise'){
            dom.className='chg rise';
            dom.style.color=QS_Style.greenFontColor;
        }else if(value<0&&dom.className!='chg down'){
            dom.className='chg down';
            dom.style.color=QS_Style.redFontColor;
        }else if((value==0||value=='--')&&dom.className!='chg'){
            dom.className='chg';
            dom.style.color='';
        }
    },
	_getChangeWidth:function(){		
		if($.browser.msie && parseInt($.browser.version) < 8){//if browser version is IE7
			var w=0,self=this;
			$.each(this.changeChildrenEl,function(i){
				w+=self.changeChildrenEl.eq(i).outerWidth(true);
			})
			return w+this.changeDomPaddingWidth;
		}else{
			return this.changeEl.outerWidth(true);
		}
	},
    changeWidth:function(data){
        if(typeof data['LastPrice']=='undefined'&&typeof data['Chg']=='undefined'){
            return;
        }
        var w=this.priceEl.outerWidth(true)+this._getChangeWidth()+10;
        if(this.width<w){// if current width< dom width, need add as a logic.
            var n=Math.ceil((w-this.width)/90);
            this.width=this.width+90*n;
            this.el.width(this.width);
            if(typeof this.callback.onWidthChange=='function'){
                this.callback.onWidthChange(this.width);
            }
            //this.container.width(this.width); 
        }
    },
    clear:function(){
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};
QS.BaseQuote={
    html:'<div class="rtq-quotes"><div class="quote-head-container"></div><div class="quote-grid-container"></div></div>',
    el:null,
    grid:null,
    gKey:null,
    head:null,
    dataScrollPN:null,
    //domMap:{is:'rw',init:{}},
    dpfMap:null,
    quoteUnique:null,
    level2El:null,
    //monitorUnqiueWidth:{is:'rw',init:false},
    dataPoints:null,
    //dataFormatMap:null,
    lastCallbackHeight:0,
    minWidth:460,
    minHeight:50,
    loaded:false,
    defaultConfig:{
        fixHeight:true,
        showHead:true,
        hasUnqiue:true,
        rowRemoveable:true,
        rowDragable:true,
        rowDropable:true,
        groupDragable:false,
        groupDropable:false
    },
    sequence:[],
    container:null,
    
    /**Methods*/
    setGKey:function(gKey){
        this.gKey=gKey;
    },
    setDataPoints:function(dps){
		var arr=[]; 
		if(this.config.licencesDataPoints){// remove the license datapoints
			for(var i=0,l=dps.length;i<l;i++){
				if(!this.config.licencesDataPoints[dps[i].val]){
					arr.push(dps[i]);
				}
			}
		}
		if(arr.length>0){
			this.dataPoints=arr;
		}else{
			this.dataPoints=dps;
		}
        
    },
    init:function(){
        if(typeof this.beforeInit=='function'){
            this.beforeInit();
        }
        if(this.config.sequence){
            this.sequence=this._convertSequence(this.config.sequence);
            this.config.sequence=[];//clear the config sequence
        }
        this.el=$(this.html).appendTo(this.container);
        if(this.config.customCls){
            this.el.addClass(this.config.customCls);
        }
        if(this.config.showHead){
             this.head=new QS.Head(this.el.find('.quote-head-container'),{isFormatName:this.config.isFormatName,showSecType:this.config.showSecType});
        }
        this._createGrid();
        if (this.config.fixHeight) {
            this.dataScrollPN = new Util.ScrollPanel(this.el.find('.quote-grid-container'), {});
        }
        var selectedDataPoints=[];
        if (this.sequence.length > 0) {
            for (var i = 0, l = this.sequence.length; i < l; i++) {
                //if(this.sequence[i]==)
                for (var j = 0, len = this.dataPoints.length; j < len; j++) {
                    if (this.dataPoints[j].val == this.sequence[i]) {
                        selectedDataPoints.push(this.dataPoints[j]);
                        break;
                    }
                }
            }
        }else{
            selectedDataPoints=this.dataPoints;
        }
        this.sequence=[];
		this.dpfMap={};
        this.addDataPoints(selectedDataPoints);
    },
	_convertSequence:function(sequence){// split range to single datapoints
		var s=[];
		for(var i=0,l=sequence.length;i<l;i++){
			if(sequence[i]=='LowPrice,HighPrice'){
				s.push('HighPrice');
				s.push('LowPrice');
			}else if(sequence[i]=='st169,st168'){
				s.push('st168');
                s.push('st169');
			}else{
				s.push(sequence[i]);
			}
		}
		return s;
	},
    _createGrid:function(){
        var self=this;
        var column= [
            { header: "Val", dataIndex: 'val',width:'100%',height:0,dataType:'string',className:'rtq-qs-hide'},            
            { header: "Txt", dataIndex: 'txt',width:'100%',height:'50%',dataType:'string',className:'rtq-qs-tt'},                
            { header: "Data", dataIndex: 'data',width:'100%',height:'50%',dataType:'float'}
        ];   
        if(this.config.rowRemoveable){
            column.push({ header: 'DEL', dataIndex: 'remove', type:'remove', renderer:'<a href="javascript:void(0)">Remove</a>' });
        }
        if(this.config.groupable){
            column.push({ header: "Group", dataIndex: 'group', hide: true});
        }
        var config= {            
            outSideHeader:true,
            column:column,          
            indexColKey:'val',
            //groupDataIndex:'Group',
            rowLayout:'grid',
            rowDragable: this.config.rowDragable,
            rowDropable: this.config.rowDropable,
            rowDragDropGroup: 'gridQuotes',
            groupDragable: this.config.groupDragable,
            groupDropable: this.config.groupDropable,
            sortDataType: 'float',
            showYScrollbar:false,
            autoWidth:true,
            autoHeight:true     
        };
        if(this.config.groupable){
            config.groupDataIndex=this.config.groupDataIndex;
        }
        this.grid=new Util.DataGrid(this.el.find('.quote-grid-container'),[],config, {
            onRowDragStart: function(e, proxy, row){
                if (row.id == 'uniquespace'||row.id == 'level2') {//provent to drag the unique
                    row.dragObj.stop();
                }else {
                    proxy.html(row.cells.txt.text);
                }
            },
            onRowRemove:function(id, row){
                self._removeSequence(id);
                if(typeof self.callback.onRemoveRow=='function'){
                    self.callback.onRemoveRow(id,row);
                }
            },
			onAfterRowRemove:function(id){
				self.changeOutSize(null,null,true);
			},
            beforeGroupDrop:function(proxy, group, toGroup){
                if (toGroup.value == 'default') {
                    proxy._stopEvent = true;
                }
            },
            afterGroupDrop:function(proxy, group, toGroup){
//                  proxy._stopEvent = false;
//                  self._setComponentContainerPosition();
            }
        }); 
        this.grid.el.addClass('quote-grid');
        if(this.config.hasUnqiue){
           var rowData={
                val:'uniquespace',
                txt:'',
                data:'',
                group:'default'
            };
            this.grid.addRow(rowData);
            var unqiueEl=this.grid.rows['uniquespace'].el.empty().addClass('rtq-grid-row-unique');
            this.quoteUnique=new QS.QuoteUnique(unqiueEl,{showNewsLink:this.config.showNewsLink,showCurrency:this.config.showCurrency,showTimeZone:this.config.showTimeZone,showExtendHour:this.config.showExtendHour},{
                onNewsClick:function(sourceCode){
                    if(typeof self.callback.onClickNewsLink=='function'){
                        self.callback.onClickNewsLink(self.gKey,sourceCode);
                    }
                },
                onWidthChange:function(w){
                    unqiueEl.width(w);
                    if (w > self.config.width) {// force change the width to show the scrollbar
                        self.grid.el.width(w);
                        self.changeOutSize(self.config.width,self.config.height,true);
                    }
                }
            });
        }
    },
    addDataPoints:function(dataPoints){
		var title=QS_Lang.quote;
        for (var i = 0, l = dataPoints.length; i < l; i++) {
            dataPoint=dataPoints[i];
            if (dataPoint.val == 'level2') {
                this.grid.addRow(dataPoint);
                var level2RowEl=this.grid.rows['level2'].el;
                level2RowEl.html('').css({
                    width:'100%',
                    height:'160px'
                });
                this.level2El=$('<div class="rtq-quotes-level2-container clearfix"><div class="comp left"><div class="comp-hd">'+title.level2ts+'</div><div class="comp-bd"></div></div><div class="comp right"><div class="comp-hd">'+title.level2md+'</div><div class="comp-bd"></div></div></div>').appendTo(this.el.find('.quote-grid-container'));
                this._setComponentContainerPosition();
            }else {
                var ndp = {};
                $.extend(true, ndp, dataPoint);
                ndp.data = QS_Formatter(this.gKey, ndp.val.split(','), ndp.dataType);
                var vals = ndp.val.split(',');
                this.grid.addRow(ndp);
                if (vals.length == 2) {
                    this.dpfMap[vals[0]] = this.dpfMap[vals[1]] = {
                        vals: vals,
                        dataType: ndp.dataType,
                        dom: this.grid.DOMMap[ndp.val]['data'],
                        showHoverTip:ndp.showHoverTip===true?true:false
                    };
                }
                else {
                    this.dpfMap[dataPoint.val] = {
                        vals: [ndp.val],
                        dataType: ndp.dataType,
                        dom: this.grid.DOMMap[ndp.val]['data'],
						showHoverTip:ndp.showHoverTip===true?true:false
                    };
                }
            }
            //this.sequence=[];
            this.sequence.push(dataPoint.val);
        }
        //this.changeOutSize();
    },
    _setComponentContainerPosition:function(){
        if(this.hasLevel2Row()){
            this.level2El.css({
                top:this.getLevel2Row().el[0].offsetTop,
                left:0
            }).show();
        }
    },
    getLevel2Row:function(){
        return this.grid.rows['level2'];
    },
    hasLevel2Row:function(){
        return !this.grid||typeof this.grid.rows['level2']=='undefined'?false:true;
    },
    getLevel2Container:function(){
        return this.level2El.find('.comp-bd');
    },
    changeHeadInfo:function(info){
        if(this.config.showHead){
            this.head.changeInfo(info);
        }
    },
    changeUniqueLastText:function(text){
        if(this.config.hasUnqiue) {
            this.quoteUnique.changeLastText(text);
        }
    },
    changeOutSize:function(w,h,flag){
        var parent = this.el.parent();
        w = w>0?w:parent.width();
        h = h>0?h:parent.height();
        var size={width:w};
        if(this.config.fixHeight){
            size.height=h;
        }
        var self = this;
        if(this.config.showHead){
            h=h-this.head.getHeight();
        }
        flag=flag===true?true:false;
        if(w!=this.config.width){
            this.config.width=w;
            flag=true;
        }
        if(h!=this.config.height){
            this.config.height=h;
            flag=true;
        }
        if(this.dataScrollPN==null){
            self._runAfterResize();
        }else{
            if(flag){
                this.dataScrollPN.reSize(w,h, function(){
                   self._runAfterResize();
                });
            }
        }
        this.onHeightChange(this.el.outerHeight(true));
    },
    _runAfterResize:function(){
        this._setComponentContainerPosition();
        if(typeof this.callback!='undefined'&&typeof this.callback.afterResize=='function'&&this.hasLevel2Row()){
            var compEl=this.level2El.find('.comp-bd').eq(0);
            this.callback.afterResize(compEl.width(),compEl.height());
        }
    },
    onHeightChange:function(height){
        if(height<this.minHeight){
            height=this.minHeight;
        }
        if (!this.loaded) {
            this.loaded = true;
            this.lastCallbackHeight = height;
            if (typeof this.callback.onLoad == 'function') {
                this.callback.onLoad({
                    component: 'quote',
                    height: height,
                    minWidth:this.minWidth,
                    minHeight:this.minHeight
                });
            }
        }else {
            if (this.lastCallbackHeight != height) {
                this.lastCallbackHeight = height;
                if (typeof this.callback.onHeightChange == 'function') {
                    this.callback.onHeightChange({
                        height: this.lastCallbackHeight,
                        component: 'quote'
                    });
                }
            }
        }
    },
    addDataPointByVal:function(val){
        var dp;
        for(var i=0,l=this.dataPoints.length;i<l;i++){
            dp=this.dataPoints[i];
            if(val==dp.val){
                this.addDataPoints([dp]);
                break;
            }
        }
		this.changeOutSize(null,null,true);
    },
    removeDataPointByVal:function(val){
        if(this._removeSequence(val)){
            delete this.dpfMap[val];//delete dpf map
            this.grid.removeRow(val,false);
        }
		this.changeOutSize(null,null,true);
    },
    addAllDataPoints:function(){
		this.removeAllDataPoints();
        this.addDataPoints(this.dataPoints);
		this.changeOutSize(null,null,true);
    },
    removeAllDataPoints:function(){
        this.dpfMap={};
        for(var i=0,l=this.sequence.length;i<l;i++){
            this.grid.removeRow(this.sequence[i],false);
        }
        this.sequence=[];
		this.changeOutSize(null,null,true);
    },
    _removeSequence:function(val){
        var index=$.inArray(val,this.sequence);
        if(index>-1){
            this.sequence.splice(index,1);
            return true;
        }
        return false;
    },
    updateData:function(data){
        var el,udata={};
        for(var field in data){
            if (this.config.hasUnqiue && this.quoteUnique.domMap[field]) {
                udata[field] = true;//QS_Formatter(this.gKey,[field],this.quoteUnique.dpfMap[field]);//data[field];
            }else {
                el = this.dpfMap[field]&&this.dpfMap[field].dom?this.dpfMap[field].dom:null;
                if (el) {
					var formatValue= QS_Formatter(this.gKey,this.dpfMap[field].vals,this.dpfMap[field].dataType);
					if(this.dpfMap[field].showHoverTip){
						formatValue='<a class="hover-cursor" href="javascript:void(0)" title="'+formatValue+'">'+formatValue+'</a>';
					}
                    el.innerHTML = formatValue;
                }
            }
        }
        if(this.config.hasUnqiue){
            this.quoteUnique.updateData(this.gKey,udata);
            this.quoteUnique.changeWidth(udata);
        }
    },
    forceUpdateUnqiueData:function(){// force update unqiue
        if (this.config.hasUnqiue&&this.gKey!=null&&gData[this.gKey]){
            var udata={};
            //var marketQuoteData=push.proxy.getMarketQuoteData(this.gKey);
            for(var field in this.quoteUnique.domMap){
				udata[field] = true;//QS_Formatter(this.gKey,[field],this.quoteUnique.dpfMap[field]);//data[field];
//                udata[field] = marketQuoteData[field] ? marketQuoteData[field] : {
//                    value: gData[this.gKey][field]
//                };
            }
            this.quoteUnique.updateData(this.gKey,udata);
            this.quoteUnique.changeWidth(udata);
        }
    },
    _judgeUnqiueWidth:function(){
        
    },
    saveConfig:function(){
        return {
            sequence:this.sequence
        }
    },
    clear:function(){
        if(this.config.showHead){
            this.head.clear();
        }
        if (this.config.hasUnqiue){
            this.quoteUnique.clear();
        }
        this.sequence=[];
        for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
        }
    }
};

QS.StockQuote=function(container,config,callback){
    this.secType='ST';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config);
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.StockQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice'])},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i'},
		{val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'])},
		{val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['LowPrice'])},
        //{val:'LowPrice,HighPrice',txt:t.dayrange,data:QS_Formatter(this.gKey,['LowPrice','HighPrice'])},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume'])},//mil
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
		{val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
		{val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
        //{val:'st169,st168',txt:t.wk52range,data:QS_Formatter(this.gKey,['st169','st168'])},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
		{val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
		{val:'sta65',txt:t.proyield,data:QS_Formatter(this.gKey,['sta65'],'%'),dataType:'%'},
        {val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%'},
        {val:'st159',txt:t.mktcap,data:QS_Formatter(this.gKey,['st159'],'dm'),dataType:'dm'},//has been divided 1000000
        {val:'sta0f',txt:t.avgvol,data:QS_Formatter(this.gKey,['sta0f'],'dm'),dataType:'dm'},
        {val:'st160',txt:t.shares,data:QS_Formatter(this.gKey,['st160'],'dm'),dataType:'dm'},
        {val:'st198',txt:t.pe,data:QS_Formatter(this.gKey,['st198'])},
        {val:'st408',txt:t.pb,data:QS_Formatter(this.gKey,['st408'])},
        {val:'st415',txt:t.ps,data:QS_Formatter(this.gKey,['st415'])},
        {val:'st410',txt:t.pcf,data:QS_Formatter(this.gKey,['st410'])},
        {val:'st263',txt:t.eps,data:QS_Formatter(this.gKey,['st263'])},
        {val:'sta44',txt:t.beta,data:QS_Formatter(this.gKey,['sta44'])},
        
        {val:'pd003',txt:t.d1ret,data:QS_Formatter(this.gKey,['pd003'],'%'),dataType:'%'},
        {val:'pd005',txt:t.w1ret,data:QS_Formatter(this.gKey,['pd005'],'%'),dataType:'%'},
        {val:'pd007',txt:t.m1ret,data:QS_Formatter(this.gKey,['pd007'],'%'),dataType:'%'},
        {val:'pd009',txt:t.m3ret,data:QS_Formatter(this.gKey,['pd009'],'%'),dataType:'%'},
        {val:'pm493',txt:t.m6ret,data:QS_Formatter(this.gKey,['pm493'],'%'),dataType:'%'},
        {val:'pd00d',txt:t.y1ret,data:QS_Formatter(this.gKey,['pd00d'],'%'),dataType:'%'},
        {val:'pd014',txt:t.y2ret,data:QS_Formatter(this.gKey,['pd014'],'%'),dataType:'%'},
        {val:'pd00f',txt:t.y3ret,data:QS_Formatter(this.gKey,['pd00f'],'%'),dataType:'%'},
        {val:'pd00h',txt:t.y5ret,data:QS_Formatter(this.gKey,['pd00h'],'%'),dataType:'%'},
        {val:'pm494',txt:t.y10ret,data:QS_Formatter(this.gKey,['pm494'],'%'),dataType:'%'},
        {val:'pm495',txt:t.y15ret,data:QS_Formatter(this.gKey,['pm495'],'%'),dataType:'%'},
        {val:'pd00b',txt:t.ytdret,data:QS_Formatter(this.gKey,['pd00b'],'%'),dataType:'%'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP'])},
        {val:'LastMarket',txt:t.texch,data:QS_Formatter(this.gKey,['LastMarket'],'exch'),dataType:'exch'},
        {val:'st200',txt:t.rating,data:QS_Formatter(this.gKey,['st200'],'star'),dataType:'star'},
        {val:'os378',txt:t.fye,data:QS_Formatter(this.gKey,['os378'])}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.ETFQuote=function(container,config,callback){
    this.secType='FE';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config);
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.ETFQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice'])},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i'},
        //{val:'LowPrice,HighPrice',txt:t.dayrange,data:QS_Formatter(this.gKey,['LowPrice','HighPrice'])},
		{val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'])},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['LowPrice'])},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume'])},
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
        //{val:'st169,st168',txt:t.wk52range,data:QS_Formatter(this.gKey,['st169','st168'])},
		{val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
		{val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%'},
        {val:'pd003',txt:t.d1ret,data:QS_Formatter(this.gKey,['pd003'],'%'),dataType:'%'},
        {val:'pd005',txt:t.w1ret,data:QS_Formatter(this.gKey,['pd005'],'%'),dataType:'%'},
        {val:'pd007',txt:t.m1ret,data:QS_Formatter(this.gKey,['pd007'],'%'),dataType:'%'},
        {val:'pd009',txt:t.m3ret,data:QS_Formatter(this.gKey,['pd009'],'%'),dataType:'%'},
        {val:'pm493',txt:t.m6ret,data:QS_Formatter(this.gKey,['pm493'],'%'),dataType:'%'},
        {val:'pd00d',txt:t.y1ret,data:QS_Formatter(this.gKey,['pd00d'],'%'),dataType:'%'},
        {val:'pd014',txt:t.y2ret,data:QS_Formatter(this.gKey,['pd014'],'%'),dataType:'%'},
        {val:'pd00f',txt:t.y3ret,data:QS_Formatter(this.gKey,['pd00f'],'%'),dataType:'%'},
        {val:'pd00h',txt:t.y5ret,data:QS_Formatter(this.gKey,['pd00h'],'%'),dataType:'%'},
        {val:'pm494',txt:t.y10ret,data:QS_Formatter(this.gKey,['pm494'],'%'),dataType:'%'},
        {val:'pm495',txt:t.y15ret,data:QS_Formatter(this.gKey,['pm495'],'%'),dataType:'%'},
        {val:'pd00b',txt:t.ytdret,data:QS_Formatter(this.gKey,['pd00b'],'%'),dataType:'%'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP'])},
        {val:'LastMarket',txt:t.texch,data:QS_Formatter(this.gKey,['LastMarket'],'exch'),dataType:'exch'},
        {val:'of009',txt:t.assets,data:QS_Formatter(this.gKey,['of009'])},
        {val:'os00m',txt:t.expenses,data:QS_Formatter(this.gKey,['os00m'],'%'),dataType:'%'},
        {val:'of028',txt:t.category,data:QS_Formatter(this.gKey,['of028'],'cat'),dataType:'cat',showHoverTip:true},
        {val:'os378',txt:t.fye,data:QS_Formatter(this.gKey,['os378'])}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.CEFQuote=function(container,config,callback){
    this.secType='FC';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config);
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.CEFQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice'])},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i'},
        //{val:'LowPrice,HighPrice',txt:t.dayrange,data:QS_Formatter(this.gKey,['LowPrice','HighPrice'])},
		{val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'])},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['LowPrice'])},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume'])},
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
        //{val:'st169,st168',txt:t.wk52range,data:QS_Formatter(this.gKey,['st169','st168'])},
		{val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
		{val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%'},
        {val:'pd003',txt:t.d1ret,data:QS_Formatter(this.gKey,['pd003'],'%'),dataType:'%'},
        {val:'pd005',txt:t.w1ret,data:QS_Formatter(this.gKey,['pd005'],'%'),dataType:'%'},
        {val:'pd007',txt:t.m1ret,data:QS_Formatter(this.gKey,['pd007'],'%'),dataType:'%'},
        {val:'pd009',txt:t.m3ret,data:QS_Formatter(this.gKey,['pd009'],'%'),dataType:'%'},
        {val:'pm493',txt:t.m6ret,data:QS_Formatter(this.gKey,['pm493'],'%'),dataType:'%'},
        {val:'pd00d',txt:t.y1ret,data:QS_Formatter(this.gKey,['pd00d'],'%'),dataType:'%'},
        {val:'pd014',txt:t.y2ret,data:QS_Formatter(this.gKey,['pd014'],'%'),dataType:'%'},
        {val:'pd00f',txt:t.y3ret,data:QS_Formatter(this.gKey,['pd00f'],'%'),dataType:'%'},
        {val:'pd00h',txt:t.y5ret,data:QS_Formatter(this.gKey,['pd00h'],'%'),dataType:'%'},
        {val:'pm494',txt:t.y10ret,data:QS_Formatter(this.gKey,['pm494'],'%'),dataType:'%'},
        {val:'pm495',txt:t.y15ret,data:QS_Formatter(this.gKey,['pm495'],'%'),dataType:'%'},
        {val:'pd00b',txt:t.ytdret,data:QS_Formatter(this.gKey,['pd00b'],'%'),dataType:'%'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP'])},
        {val:'of009',txt:t.assets,data:QS_Formatter(this.gKey,['of009'])},
        {val:'os00m',txt:t.expenses,data:QS_Formatter(this.gKey,['os00m'],'%'),dataType:'%'},
        {val:'of028',txt:t.category,data:QS_Formatter(this.gKey,['of028'],'cat'),dataType:'cat',showHoverTip:true},
        {val:'hs05a',txt:t.eqstyle,data:QS_Formatter(this.gKey,['hs05a'],'sty'),dataType:'sty'},
        {val:'os378',txt:t.fye,data:QS_Formatter(this.gKey,['os378'])}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.MFQuote=function(container,config,callback){
    this.secType='FO';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config);
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.MFQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
        //{val:'st169,st168',txt:t.wk52range,data:QS_Formatter(this.gKey,['st169','st168'])},
		{val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
		{val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%'},
		{val:'pd003',txt:t.d1ret,data:QS_Formatter(this.gKey,['pd003'],'%'),dataType:'%'},
        {val:'pd005',txt:t.w1ret,data:QS_Formatter(this.gKey,['pd005'],'%'),dataType:'%'},
        {val:'pd007',txt:t.m1ret,data:QS_Formatter(this.gKey,['pd007'],'%'),dataType:'%'},
        {val:'pd009',txt:t.m3ret,data:QS_Formatter(this.gKey,['pd009'],'%'),dataType:'%'},
        {val:'pm493',txt:t.m6ret,data:QS_Formatter(this.gKey,['pm493'],'%'),dataType:'%'},
        {val:'pd00d',txt:t.y1ret,data:QS_Formatter(this.gKey,['pd00d'],'%'),dataType:'%'},
        {val:'pd014',txt:t.y2ret,data:QS_Formatter(this.gKey,['pd014'],'%'),dataType:'%'},
        {val:'pd00f',txt:t.y3ret,data:QS_Formatter(this.gKey,['pd00f'],'%'),dataType:'%'},
        {val:'pd00h',txt:t.y5ret,data:QS_Formatter(this.gKey,['pd00h'],'%'),dataType:'%'},
        {val:'pm494',txt:t.y10ret,data:QS_Formatter(this.gKey,['pm494'],'%'),dataType:'%'},
        {val:'pm495',txt:t.y15ret,data:QS_Formatter(this.gKey,['pm495'],'%'),dataType:'%'},
        {val:'pd00b',txt:t.ytdret,data:QS_Formatter(this.gKey,['pd00b'],'%'),dataType:'%'},
		/*
        {val:'rr01g',txt:t.y3ret,data:QS_Formatter(this.gKey,['rr01g'],'%'),dataType:'%'},
        {val:'rr01l',txt:t.y5ret,data:QS_Formatter(this.gKey,['rr01l'],'%'),dataType:'%'},
        {val:'rr01k',txt:t.y10ret,data:QS_Formatter(this.gKey,['rr01k'],'%'),dataType:'%'},*/
        {val:'of009',txt:t.assets,data:QS_Formatter(this.gKey,['of009'])},
        {val:'os463',txt:t.load,data:QS_Formatter(this.gKey,['os463'])},
        {val:'os00m',txt:t.expenses,data:QS_Formatter(this.gKey,['os00m'],'%'),dataType:'%'},
        {val:'os03s',txt:t.turnover,data:QS_Formatter(this.gKey,['os03s'],'%'),dataType:'%'},
        {val:'os388',txt:t.mininv,data:QS_Formatter(this.gKey,['os388'])},
        {val:'of028',txt:t.category,data:QS_Formatter(this.gKey,['of028'],'cat'),dataType:'cat',showHoverTip:true},
        {val:'hs05a',txt:t.eqstyle,data:QS_Formatter(this.gKey,['hs05a'],'sty'),dataType:'sty'},
        {val:'hs00l',txt:t.fistyle,data:QS_Formatter(this.gKey,['hs00l'],'sty'),dataType:'sty'},
        {val:'st200',txt:t.rating,data:QS_Formatter(this.gKey,['st200'],'star'),dataType:'star'},
        {val:'os378',txt:t.fye,data:QS_Formatter(this.gKey,['os378'])}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.IndexQuote=function(container,config,callback){
    this.secType='XI';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config);
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.IndexQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[
        //{val:'LowPrice,HighPrice',txt:t.dayrange,data:QS_Formatter(this.gKey,['LowPrice','HighPrice'])},
		{val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'])},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['LowPrice'])},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume'])},//mil
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
        //{val:'st169,st168',txt:t.wk52range,data:QS_Formatter(this.gKey,['st169','st168'])},
		{val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
		{val:'pd003',txt:t.d1ret,data:QS_Formatter(this.gKey,['pd003'],'%'),dataType:'%'},
        {val:'pd005',txt:t.w1ret,data:QS_Formatter(this.gKey,['pd005'],'%'),dataType:'%'},
        {val:'pd007',txt:t.m1ret,data:QS_Formatter(this.gKey,['pd007'],'%'),dataType:'%'},
        {val:'pd009',txt:t.m3ret,data:QS_Formatter(this.gKey,['pd009'],'%'),dataType:'%'},
        {val:'pm493',txt:t.m6ret,data:QS_Formatter(this.gKey,['pm493'],'%'),dataType:'%'},
        {val:'pd00d',txt:t.y1ret,data:QS_Formatter(this.gKey,['pd00d'],'%'),dataType:'%'},
        {val:'pd014',txt:t.y2ret,data:QS_Formatter(this.gKey,['pd014'],'%'),dataType:'%'},
        {val:'pd00f',txt:t.y3ret,data:QS_Formatter(this.gKey,['pd00f'],'%'),dataType:'%'},
        {val:'pd00h',txt:t.y5ret,data:QS_Formatter(this.gKey,['pd00h'],'%'),dataType:'%'},
        {val:'pm494',txt:t.y10ret,data:QS_Formatter(this.gKey,['pm494'],'%'),dataType:'%'},
        {val:'pm495',txt:t.y15ret,data:QS_Formatter(this.gKey,['pm495'],'%'),dataType:'%'},
        {val:'pd00b',txt:t.ytdret,data:QS_Formatter(this.gKey,['pd00b'],'%'),dataType:'%'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP'])},
        {val:'LastMarket',txt:t.texch,data:QS_Formatter(this.gKey,['LastMarket'],'exch'),dataType:'exch'},
        {val:'hs05a',txt:t.eqstyle,data:QS_Formatter(this.gKey,['hs05a'],'sty'),dataType:'sty'}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.ForexQuote=function(container,config,callback){
    this.secType='FX';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,{showCurrency:false,showTimeZone:true,isFormatName:false},config);
    }
	this.config.showExtendHour=true;
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.ForexQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'sf'),dataType:'sf'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice'],'sf'),dataType:'sf'},
        {val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'],'sf'),dataType:'sf'},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['HighPrice'],'sf'),dataType:'sf'},
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'],'sf'),dataType:'sf'},
        {val:'exch',txt:t.exch,data:QS_Formatter(this.gKey,['exch'],'s'),dataType:'s'}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.TUSStockQuote=function(container,config,callback){
    this.customCls='rtq-quotes-custom';
    this.template='USST';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config,{
            groupable:true,
            groupDataIndex:'group',
            showNewsLink:true
        })
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.TUSStockQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice']),group:'default'},
        {val:'BidMarket',txt:t.bidexch,data:QS_Formatter(this.gKey,['BidMarket']),dataType:'exch',group:'default'},
        {val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2',group:'default'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i',group:'default'},
        {val:'AskMarket',txt:t.askexch,data:QS_Formatter(this.gKey,['AskMarket'],'exch'),dataType:'exch',group:'default'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice']),group:'default'},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i',group:'default'},
        {val:'BTC',txt:t.btc,data:QS_Formatter(this.gKey,['BTC']),group:'default'},
        {val:'LastVolume',txt:t.lastvolume,data:QS_Formatter(this.gKey,['LastVolume'],'i'),dataType:'i',group:'default'},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice']),group:'default'},
        {val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume']),group:'default'},//mil
        {val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168']),group:'default'},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169']),group:'default'},
        {val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109']),group:'default'},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106']),group:'default'},
        // GROUP 'a' 
        {val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%',group:'a'},
        {val:'DivShare',txt:t.divshare,data:QS_Formatter(this.gKey,['DivShare']),group:'a'},
        {val:'st476',txt:t.divexdate,data:QS_Formatter(this.gKey,['st476'],'s'),dataType:'s',group:'a'},
        {val:'sta44',txt:t.beta,data:QS_Formatter(this.gKey,['sta44']),group:'a'},
        {val:'st263',txt:t.eps,data:QS_Formatter(this.gKey,['st263']),group:'a'},
        {val:'st198',txt:t.pe,data:QS_Formatter(this.gKey,['st198']),group:'a'},
        {val:'ConsEst',txt:t.consest,data:QS_Formatter(this.gKey,['ConsEst']),group:'a'},
        {val:'FPE',txt:t.fwdpe,data:QS_Formatter(this.gKey,['FPE']),group:'a'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP']),group:'a'},
        
        //group 'b'
        {val:'st159',txt:t.mktcap,data:QS_Formatter(this.gKey,['st159'],'dm'),dataType:'dm',group:'b'},//has been divided 1000000
        
        //group 'c'
        {val:'QRQ',txt:t.qrq,data:QS_Formatter(this.gKey,['QRQ']),group:'c'},
        {val:'Mstar',txt:t.mstar,data:QS_Formatter(this.gKey,['Mstar']),group:'c'},
        {val:'S&P',txt:t.sp,data:QS_Formatter(this.gKey,['S&P']),group:'c'},
        
        //group 'd'
        {val:'PriceObj',txt:t.priceobj,data:QS_Formatter(this.gKey,['PriceObj']),group:'d'},
        {val:'POED',txt:t.poestdate,data:QS_Formatter(this.gKey,['POED']),group:'d'},
        {val:'FY1EPS',txt:t.fy1eps,data:QS_Formatter(this.gKey,['FY1EPS']),group:'d'},
        {val:'FY2EPS',txt:t.fy2eps,data:QS_Formatter(this.gKey,['FY2EPS']),group:'d'},
        
        //GROUP 'E'
        {val:'MLSecNum',txt:t.mlsecnum,data:QS_Formatter(this.gKey,['MLSecNum']),group:'e'},
        {val:'MLSymbol',txt:t.mlsymbol,data:QS_Formatter(this.gKey,['MLSymbol']),group:'e'},
        {val:'ISIN',txt:t.isin,data:QS_Formatter(this.gKey,['ISIN'],'s'),dataType:'s',group:'e'},
        {val:'CUSIP',txt:t.cusip,data:QS_Formatter(this.gKey,['CUSIP'],'s'),dataType:'s',group:'e'}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.THKStockQuote=function(container,config,callback){
    this.customCls='rtq-quotes-custom';
    this.template='HKST';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config,{
            groupable:true,
            groupDataIndex:'group',
            showNewsLink:true
        })
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.THKStockQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice']),group:'default'},
        {val:'BidMarket',txt:t.bidexch,data:QS_Formatter(this.gKey,['BidMarket']),dataType:'exch',group:'default'},
        {val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2',group:'default'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i',group:'default'},
        {val:'AskMarket',txt:t.askexch,data:QS_Formatter(this.gKey,['AskMarket'],'exch'),dataType:'exch',group:'default'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice']),group:'default'},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i',group:'default'},
        {val:'BTC',txt:t.btc,data:QS_Formatter(this.gKey,['BTC']),group:'default'},
        {val:'LastVolume',txt:t.lastvolume,data:QS_Formatter(this.gKey,['LastVolume'],'i'),dataType:'i',group:'default'},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice']),group:'default'},
        {val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume']),group:'default'},//mil
        {val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168']),group:'default'},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169']),group:'default'},
		{val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109']),group:'default'},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106']),group:'default'},
        
        // GROUP 'a' 
        {val:'sta44',txt:t.beta,data:QS_Formatter(this.gKey,['sta44']),group:'a'},
        {val:'st263',txt:t.eps,data:QS_Formatter(this.gKey,['st263']),group:'a'},
        {val:'st198',txt:t.pe,data:QS_Formatter(this.gKey,['st198']),group:'a'},
        {val:'ConsEst',txt:t.consest,data:QS_Formatter(this.gKey,['ConsEst']),group:'a'},
        {val:'FPE',txt:t.fwdpe,data:QS_Formatter(this.gKey,['FPE']),group:'a'},
       
       //GROUP 'B'
        {val:'Nominal',txt:t.nominal,data:QS_Formatter(this.gKey,['Nominal']),group:'b'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP']),group:'b'},
        {val:'VWAPVOL',txt:t.vmapvol,data:QS_Formatter(this.gKey,['VWAPVOL']),group:'b'},
        {val:'Accvol',txt:t.accvol,data:QS_Formatter(this.gKey,['Accvol']),group:'b'},
        {val:'D437',txt:t.turnover,data:QS_Formatter(this.gKey,['D437']),group:'b'},
        //group 'c'
        {val:'st159',txt:t.mktcap,data:QS_Formatter(this.gKey,['st159'],'dm'),dataType:'dm',group:'c'},//has been divided 1000000
        {val:'12moeps',txt:t.mo12eps,data:QS_Formatter(this.gKey,['12moeps']),group:'c'},
        {val:'EPSFY1',txt:t.epsfy1,data:QS_Formatter(this.gKey,['EPSFY1']),group:'c'},
        {val:'EPSFY2',txt:t.epsfy2,data:QS_Formatter(this.gKey,['EPSFY1']),group:'c'},
        {val:'PEFY1',txt:t.pefy1,data:QS_Formatter(this.gKey,['PEFY1']),group:'c'},
        {val:'PEFY2',txt:t.pefy2,data:QS_Formatter(this.gKey,['PEFY2']),group:'c'},
        
        //GROUP 'D'
        {val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%',group:'d'},
        {val:'DivShare',txt:t.divshare,data:QS_Formatter(this.gKey,['DivShare']),group:'d'},
        {val:'st476',txt:t.divexdate,data:QS_Formatter(this.gKey,['st476'],'s'),dataType:'s',group:'d'},
        {val:'S8',txt:t.lotsize,data:QS_Formatter(this.gKey,['S8'],'d'),dataType:'d',group:'d'},
        {val:'Spread',txt:t.spread,data:QS_Formatter(this.gKey,['Spread'],'d'),dataType:'d',group:'d'},
        
        //group 'level2'
        {val:'level2',txt:'',data:'--',dataType:'s',group:'level2'},
        
        //group 'f'
        {val:'QRQ',txt:t.qrq,data:QS_Formatter(this.gKey,['QRQ']),group:'f'},
        {val:'Mstar',txt:t.mstar,data:QS_Formatter(this.gKey,['Mstar']),group:'f'},
        {val:'S&P',txt:t.sp,data:QS_Formatter(this.gKey,['S&P']),group:'f'},
        
        //group 'g'
        {val:'PriceObj',txt:t.priceobj,data:QS_Formatter(this.gKey,['PriceObj']),group:'g'},
        {val:'POED',txt:t.poestdate,data:QS_Formatter(this.gKey,['POED']),group:'g'},
        {val:'FY1EPS',txt:t.fy1eps,data:QS_Formatter(this.gKey,['FY1EPS']),group:'g'},
        {val:'FY2EPS',txt:t.fy2eps,data:QS_Formatter(this.gKey,['FY2EPS']),group:'g'},
        
        //GROUP 'h'
        {val:'MLSecNum',txt:t.mlsecnum,data:QS_Formatter(this.gKey,['MLSecNum']),group:'h'},
        {val:'MLSymbol',txt:t.mlsymbol,data:QS_Formatter(this.gKey,['MLSymbol']),group:'h'},
        {val:'ISIN',txt:t.isin,data:QS_Formatter(this.gKey,['ISIN'],'s'),dataType:'s',group:'h'},
        {val:'CUSIP',txt:t.cusip,data:QS_Formatter(this.gKey,['CUSIP'],'s'),dataType:'s',group:'h'}
        ];
        this.setDataPoints(dataPoints);
    }
});


QS.TSGStockQuote=function(container,config,callback){
    this.customCls='rtq-quotes-custom';
    this.template='SGST';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config,{
            groupable:true,
            groupDataIndex:'group',
            showNewsLink:true
        })
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.TSGStockQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[{val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice']),group:'default'},
        {val:'BidMarket',txt:t.bidexch,data:QS_Formatter(this.gKey,['BidMarket']),dataType:'exch',group:'default'},
        {val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2',group:'default'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i',group:'default'},
        {val:'AskMarket',txt:t.askexch,data:QS_Formatter(this.gKey,['AskMarket'],'exch'),dataType:'exch',group:'default'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice']),group:'default'},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i',group:'default'},
        {val:'BTC',txt:t.btc,data:QS_Formatter(this.gKey,['BTC']),group:'default'},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice']),group:'default'},
        {val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['HighPrice']),group:'default'},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume']),group:'default'},//mil
        {val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168']),group:'default'},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169']),group:'default'},
		{val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109']),group:'default'},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106']),group:'default'},
        {val:'D437',txt:t.turnover,data:QS_Formatter(this.gKey,['D437']),group:'default'},
        {val:'OfficialClose',txt:t.offclose,data:QS_Formatter(this.gKey,['OfficialClose']),group:'default'},
        {val:'ClosingBid',txt:t.colsebid,data:QS_Formatter(this.gKey,['ClosingBid']),group:'default'},
        {val:'ClosingAsk',txt:t.colseask,data:QS_Formatter(this.gKey,['ClosingAsk']),group:'default'},
        {val:'Moves',txt:t.moves,data:QS_Formatter(this.gKey,['Moves']),group:'default'},
        
        // GROUP 'a' 
        {val:'sta44',txt:t.beta,data:QS_Formatter(this.gKey,['sta44']),group:'a'},
        {val:'st263',txt:t.eps,data:QS_Formatter(this.gKey,['st263']),group:'a'},
        {val:'st198',txt:t.pe,data:QS_Formatter(this.gKey,['st198']),group:'a'},
        {val:'ConsEst',txt:t.consest,data:QS_Formatter(this.gKey,['ConsEst']),group:'a'},
        {val:'FPE',txt:t.fwdpe,data:QS_Formatter(this.gKey,['FPE']),group:'a'},
       
       //GROUP 'B'
        {val:'Nominal',txt:t.nominal,data:QS_Formatter(this.gKey,['Nominal']),group:'b'},
        {val:'VWAP',txt:t.vwap,data:QS_Formatter(this.gKey,['VWAP']),group:'b'},
        {val:'VWAPVOL',txt:t.vmapvol,data:QS_Formatter(this.gKey,['VWAPVOL']),group:'b'},
        {val:'Accvol',txt:t.accvol,data:QS_Formatter(this.gKey,['Accvol']),group:'b'},
       
        //group 'c'
        {val:'st159',txt:t.mktcap,data:QS_Formatter(this.gKey,['st159'],'dm'),dataType:'dm',group:'c'},//has been divided 1000000
        {val:'12moeps',txt:t.mo12eps,data:QS_Formatter(this.gKey,['12moeps']),group:'c'},
        {val:'EPSFY1',txt:t.epsfy1,data:QS_Formatter(this.gKey,['EPSFY1']),group:'c'},
        {val:'EPSFY2',txt:t.epsfy2,data:QS_Formatter(this.gKey,['EPSFY1']),group:'c'},
        {val:'PEFY1',txt:t.pefy1,data:QS_Formatter(this.gKey,['PEFY1']),group:'c'},
        {val:'PEFY2',txt:t.pefy2,data:QS_Formatter(this.gKey,['PEFY2']),group:'c'},
        
        //GROUP 'D'
        {val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%',group:'d'},
        {val:'DivShare',txt:t.divshare,data:QS_Formatter(this.gKey,['DivShare']),group:'d'},
        {val:'st476',txt:t.divexdate,data:QS_Formatter(this.gKey,['st476'],'s'),dataType:'s',group:'d'},
        {val:'S8',txt:t.lotsize,data:QS_Formatter(this.gKey,['S8'],'d'),dataType:'d',group:'d'},
        {val:'Spread',txt:t.spread,data:QS_Formatter(this.gKey,['Spread'],'d'),dataType:'d',group:'d'},
        
        //group 'level2'
        {val:'level2',txt:'',data:'--',dataType:'s',group:'level2'},
        
        //group 'f'
        {val:'QRQ',txt:t.qrq,data:QS_Formatter(this.gKey,['QRQ']),group:'f'},
        {val:'Mstar',txt:t.mstar,data:QS_Formatter(this.gKey,['Mstar']),group:'f'},
        {val:'S&P',txt:t.sp,data:QS_Formatter(this.gKey,['S&P']),group:'f'},
        
        //group 'g'
        {val:'PriceObj',txt:t.priceobj,data:QS_Formatter(this.gKey,['PriceObj']),group:'g'},
        {val:'POED',txt:t.poestdate,data:QS_Formatter(this.gKey,['POED']),group:'g'},
        {val:'FY1EPS',txt:t.fy1eps,data:QS_Formatter(this.gKey,['FY1EPS']),group:'g'},
        {val:'FY2EPS',txt:t.fy2eps,data:QS_Formatter(this.gKey,['FY2EPS']),group:'g'},
        
        //GROUP 'h'
        {val:'MLSecNum',txt:t.mlsecnum,data:QS_Formatter(this.gKey,['MLSecNum']),group:'h'},
        {val:'MLSymbol',txt:t.mlsymbol,data:QS_Formatter(this.gKey,['MLSymbol']),group:'h'},
        {val:'ISIN',txt:t.isin,data:QS_Formatter(this.gKey,['ISIN'],'s'),dataType:'s',group:'h'},
        {val:'CUSIP',txt:t.cusip,data:QS_Formatter(this.gKey,['CUSIP'],'s'),dataType:'s',group:'h'}
        ];
        this.setDataPoints(dataPoints);
    }
});

QS.TSNAPQuote=function(container,config,callback){
    this.customCls='rtq-quotes-custom';
    this.template='SNAP';
    this.container=container;
    this.config={};
    this.callback={};
    if(config){
        $.extend(true,this.config,this.defaultConfig,config,{
            groupable:false
        })
    }
    if(callback){
        $.extend(true,this.callback,callback)
    }
};
QS.TSNAPQuote.prototype=$.extend(true,{},QS.BaseQuote,{
    beforeInit:function(){
		var t=QS_Lang.quote;
        var dataPoints=[
        {val:'BidMarket',txt:t.bidexch,data:QS_Formatter(this.gKey,['BidMarket']),dataType:'exch'},
        {val:'BidPrice',txt:t.bidprice,data:QS_Formatter(this.gKey,['BidPrice'],'f2'),dataType:'f2'},
        {val:'BidSize',txt:t.bidsize,data:QS_Formatter(this.gKey,['BidSize'],'i'),dataType:'i'},
        {val:'AskMarket',txt:t.askexch,data:QS_Formatter(this.gKey,['AskMarket'],'exch'),dataType:'exch'},
        {val:'AskPrice',txt:t.askprice,data:QS_Formatter(this.gKey,['AskPrice'])},
        {val:'AskSize',txt:t.asksize,data:QS_Formatter(this.gKey,['AskSize'],'i'),dataType:'i'},
        {val:'LastVolume',txt:t.lastvolume,data:QS_Formatter(this.gKey,['LastVolume'],'i'),dataType:'i'},
        {val:'QRQ',txt:t.qrq,data:QS_Formatter(this.gKey,['QRQ'])},
        {val:'OpenPrice',txt:t.openprice,data:QS_Formatter(this.gKey,['OpenPrice'])},
        {val:'HighPrice',txt:t.highprice,data:QS_Formatter(this.gKey,['HighPrice'])},
        {val:'LowPrice',txt:t.lowprice,data:QS_Formatter(this.gKey,['HighPrice'])},
        {val:'Volume',txt:t.volume,data:QS_Formatter(this.gKey,['Volume'])},//mil
        {val:'st168',txt:t.wk52high,data:QS_Formatter(this.gKey,['st168'])},
        {val:'st169',txt:t.wk52low,data:QS_Formatter(this.gKey,['st169'])},
		{val:'st109',txt:t.wk52hdate,data:QS_Formatter(this.gKey,['st109'])},
        {val:'st106',txt:t.wk52ldate,data:QS_Formatter(this.gKey,['st106'])},
        {val:'ClosePrice',txt:t.prevclose,data:QS_Formatter(this.gKey,['ClosePrice'])},
        {val:'Mstar',txt:t.mstar,data:QS_Formatter(this.gKey,['Mstar'])},
        {val:'pm032',txt:t.divyield,data:QS_Formatter(this.gKey,['pm032'],'%'),dataType:'%'},
        {val:'st476',txt:t.divexdate,data:QS_Formatter(this.gKey,['st476'],'s'),dataType:'s'},
        {val:'S&P',txt:t.sp,data:QS_Formatter(this.gKey,['S&P'])},
        {val:'PriceObj',txt:t.priceobj,data:QS_Formatter(this.gKey,['PriceObj'])},
        {val:'st198',txt:t.pe,data:QS_Formatter(this.gKey,['st198'])},
        {val:'st263',txt:t.eps,data:QS_Formatter(this.gKey,['st263'])},
        {val:'sta44',txt:t.beta,data:QS_Formatter(this.gKey,['sta44'])}
        ];
        this.setDataPoints(dataPoints);
    }
});
QS.Quote=function(container,config,callback){
    this.gKey=null;
    this.ticker=null;
    this.lastGKey=null;
    this.quoteWidget=null;
    this.container=container;
    this.config={instid:'QSDEMO'};
    this.callback={};
    if(config){
        $.extend(true,this.config,config);
    }
    if(callback){
        $.extend(true,this.callback,callback);
    }
};
QS.Quote.prototype={
    init:function(){
        if(this.ticker&&this.ticker!=''){
            this.acceptTicker();
        }else{
			this._switchQuoteWidget(this.config.key);
			/*
            this.quoteWidget=new QS.StockQuote(this.container,this.config,this.callback);
            this.quoteWidget.init();
            this.changeOutSize(this.config.width,this.config.height,true);
            if(typeof this.callback.afterInit=='function'){
                this.callback.afterInit();
            }*/
        }
    },
    setTicker:function(ticker){
        this.ticker=ticker;
    },
    hasLevel2Row:function(){
        return this.quoteWidget.hasLevel2Row();
    },
    getLevel2Container:function(){
        return this.quoteWidget.getLevel2Container();
    },
    getDataPoints:function(){
        return this.quoteWidget.dataPoints;
    },
    getSelectedDataPoints:function(){
        return this.quoteWidget.selectedDataPoints;
    },
    getSequence:function(){
        return this.quoteWidget.sequence;
    },
    addDataPointByVal:function(val){
        this.quoteWidget.addDataPointByVal(val);
    },
    removeDataPointByVal:function(val){
        this.quoteWidget.removeDataPointByVal(val);
    },
    addAllDataPoints:function(){
        this.quoteWidget.addAllDataPoints();
    },
    removeAllDataPoints:function(){
        this.quoteWidget.removeAllDataPoints();
    },
    saveConfig:function(){
        var key=this.quoteWidget.secType;
        if(!key){
            key=this.quoteWidget.template;
        }
        var sequence={};
        if (key) {
            sequence[key] = this.quoteWidget.sequence;
        }
        return {
            ticker:this.ticker,
            sequence:sequence,
            key:key
        }
    },
    clear:function(){
       if(typeof this.callback.beforeClear=='function'){
           this.callback.beforeClear();
       }
       if(this.quoteWidget){
           this.quoteWidget.clear();        
       }
       for(var p in this){
            if(!p || p == 'clear'){continue;}
            this[p] = null;
            delete this[p];
       }
    },
    updateData:function(gKey,data){
        if (this.gKey == gKey&&this.quoteWidget!=null&&this.quoteWidget.gKey==gKey) {
            this.quoteWidget.updateData(data);
        }
    },
    changeOutSize:function(w,h,flag){
        if(w>0&&w!=this.config.width){
            this.config.width=w;
        }
        if(h>0&&h!=this.config.height){
            this.config.height=h;
        }
        this.quoteWidget.changeOutSize(w,h,flag);
    },
    autoCPCallback:function(o){
        this.acceptTicker(o);
    },
    acceptTicker:function(ticker){
        var self=this;
        if(this.ticker!=ticker){
            this.tValidation.checkTickers(ticker||this.ticker,function(o){
                self.validateCallback(o);
            });
        }
    },
    validateCallback:function(gkeyList){
        var self=this,d;
        if(!gkeyList||gkeyList.length==0){ // the ticker is invalid
            if(this.__winObj&&this.__winObj.searchEl){
               if(this.gKey&&gData[this.lastGKey]){
                  this.__winObj.searchEl.find("#"+this.__winObj._autoBoxID).val(gData[this.lastGKey]["ticker"]);
               }
            }
        }
        this.lastGKey=this.gKey;
        this.gKey=gkeyList[0];
        d = gData[this.gKey] ? gData[this.gKey] : gData[gIdMap[this.gKey]];
        if(d){
            if(this.lastGKey){
                this.tValidation.unSubscribe([this.lastGKey ]);//unscribe the last ticker
            }
            this.ticker=d['performanceId']||d['secId'];
            var mType=d['mType'],tenforeCode=this.gKey.split(":")[0];
            if(typeof this.setTitle=='function'){
                this.setTitle('Quote:',d.ticker);
            }
            getStaticData([this.ticker], function(o){
                self._switchQuoteWidget(mType,tenforeCode);
                var symbol=d.clientTicker||d.ticker;
                if(d.tenforeCode&&gExchangeMap[d.tenforeCode]&&gExchangeMap[d.tenforeCode]!='NA'){
                    var exch=gExchangeMap[d.tenforeCode];
                    symbol=exch+":"+symbol;
                }
                self.quoteWidget.changeHeadInfo({
                    companyName:d.Name|| "",
                    symbol:symbol||"",
					secType:mType||""
                });
                if (typeof self.callback.afterAcceptTicker=='function') {
                    self.callback.afterAcceptTicker(self.gKey?self.gKey : '', self.lastGKey);
                }
                self.changeOutSize(self.config.width,self.config.height);
            });
        }
    },
    _emptyQuoteWidget:function(){
        this.quoteWidget.clear();
        this.quoteWidget=null;
        delete this.quoteWidget;
        this.container[0].innerHTML='';
    },
    _switchQuoteWidget:function(sType,tCode){
		var t=QS_Lang.quote;
        var needReCreate=false,needClear=false,key=this.config.key||this.config.securityType;
        if (!this.quoteWidget) {
            needReCreate = true;
        }else {
            if (this.config.template!=''&&this.quoteWidget.template != this.config.template) {
                needReCreate = true;
                needClear=true;
                key=this.config.template;
            }else {
                if(this.quoteWidget.secType!=sType){
                    needReCreate = true;
                    needClear=true;
                    key=sType;
                }
            }
        }
        var config=$.extend(true,{},this.config);
        if(config.sequence&&key){
            config.sequence=config.sequence[key]||[];
        }
		if(config.customCls){
			config.customCls=config.customCls+"-"+(config.template||sType||'ST');
		}
        if(needClear){
            this._emptyQuoteWidget();
        }
        if(needReCreate){
            if(config.template=='USST'){
                this.quoteWidget=new QS.TUSStockQuote(this.container,config,this.callback);
            }else if(config.template=='HKST'){
                this.quoteWidget=new QS.THKStockQuote(this.container,config,this.callback);
            }else if(config.template=='SGST'){
                this.quoteWidget=new QS.TSGStockQuote(this.container,config,this.callback);
            }else if(config.template=='SNAP'){
                this.quoteWidget=new QS.TSNAPQuote(this.container,config,this.callback);
            }else{
                if(sType=='FE'){
                    this.quoteWidget=new QS.ETFQuote(this.container,config,this.callback);
                }else if(sType=='FC'){
                    this.quoteWidget=new QS.CEFQuote(this.container,config,this.callback);
                }else if(sType=='FO'){
                    this.quoteWidget=new QS.MFQuote(this.container,config,this.callback);
                }else if(sType=='XI'){
                    this.quoteWidget=new QS.IndexQuote(this.container,config,this.callback);
                }else if(sType=='FX'){
                    this.quoteWidget=new QS.ForexQuote(this.container,config,this.callback);
                }else{
                    this.quoteWidget=new QS.StockQuote(this.container,config,this.callback);
                }
            }
            this.quoteWidget.setGKey(this.gKey);
            this.quoteWidget.init();
            if(typeof this.callback.afterInit=='function'){
                this.callback.afterInit(true);
            }
            this.quoteWidget.changeUniqueLastText(sType=='FO'?t.lastnav:t.qlastprice);
            this.changeOutSize(this.config.width,this.config.height,true);
        }else{
            this.quoteWidget.setGKey(this.gKey);
            if(typeof this.callback.afterInit=='function'){
                this.callback.afterInit(false);
            }
        }
        this.quoteWidget.forceUpdateUnqiueData();
        this.quoteWidget.updateData(this.quoteWidget.dpfMap);
    }
};
